<template>
	<el-form ref="form" :model="form" label-width="80px" @submit.prevent="onSubmit" style="margin:20px;width:60%;min-width:600px;">
		<el-form-item label="网站名">
			<el-input v-model="form.sitename"></el-input>
		</el-form-item>
		<el-form-item label="URL">
			<el-input v-model="form.siteurl">
			<template slot="prepend">http://</template>
			</el-input>
		</el-form-item>
		<el-form-item label="初始金钱">
			<el-input v-model="form.initgold">
			<template slot="append">$</template>
			</el-input>
		</el-form-item>
		<el-form-item label="发帖经验">
			<el-input v-model="form.getexp">
			<template slot="append">E</template>
			</el-input>
		</el-form-item>
		<el-form-item label="经验消耗">
			<el-input v-model="form.postexp">
			<template slot="append">E</template>
			</el-input>
		</el-form-item>
		<el-form-item label="版权信息">
			<el-input v-model="form.mycopyright"></el-input>
		</el-form-item>
		<el-form-item label="关键词">
			<el-input v-model="form.mykeywords"></el-input>
		</el-form-item>
		<el-form-item label="描述">
			<el-input v-model="form.mydesc"></el-input>
		</el-form-item>
		<el-form-item label="是否关站">
			<el-radio-group v-model="form.isoff">
				<el-radio :label="1">是</el-radio>
				<el-radio :label="0">否</el-radio>
			</el-radio-group>
		</el-form-item>
		<el-form-item label="关站原因">
			<el-input type="textarea"
			:autosize="{ minRows: 2, maxRows: 4}"
			 v-model="form.offreason"></el-input>
		</el-form-item>
		<el-form-item>
			<el-button type="primary" @click="handleCreate()">修改</el-button>
			<el-button @click.native.prevent>取消</el-button>
		</el-form-item>
	</el-form>
</template>

<script>

	import { getBasicSetting, setBasicSetting } from '../../api/api';

	export default {
		data() {
			return {
				form: {
					sitename: '',
					siteurl: '',
					mycopyright: '',
					mykeywords: '',
					mydesc: '',
					isoff: false,
					offreason: '',
					initgold: '',
					postexp: '',
					getexp: ''
				}
			}
		},
		methods: {
			onSubmit() {
				console.log('submit!');
			},
			//获取系统信息
			getInfo() {
				this.listLoading = true;
				//NProgress.start();
				getBasicSetting().then((res) => {
					this.form = res.data;
					this.listLoading = false;
				}).catch((error) => {
					this.$notify.error({
					title: '无法连接到服务器',
					message: '请检查您的网络连接，稍后重试'
					});
				});
			},
			handleCreate: function () {
				this.$confirm('确认修改吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = this.form;
					console.log(para);
					setBasicSetting(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						if(res.data.id == 0){
							this.$message({
								message: res.data.message,
								type: 'success'
							});
							this.getInfo();
						}else if(res.data.id == 1){
							this.$message({
								message: res.data.message,
								type: 'danger'
							});
						}
					}).catch((error) => {
						this.$notify.error({
							title: '无法连接到服务器',
							message: '请检查您的网络连接，稍后重试'
						});
					});
				}).catch(() => {

				});
			},
		},
		mounted() {
			this.getInfo();
		}
	}

</script>